package models

import (
	"gorm.io/gorm"
	"time"
)

func (ReportDayMaterial) TableName() string {
	return "report_day_material"
}

func (ReportDayMaterialJln) TableName() string { return "report_day_material_jln" }

type ReportDayMaterialJln struct {
	ReportDayMaterial
}

type ReportDayMaterial struct {
	ID                 int     `gorm:"primarykey" json:"id"`
	CreateTime         string  `json:"create_time"`
	UpdateTime         string  `json:"update_time"`
	MediaId            int     `json:"media_id,omitempty"`
	CompanyId          int     `json:"company_id,omitempty"`
	MediaAccountId     int     `json:"media_account_id,omitempty"`
	AdvertiserId       int64   `json:"advertiser_id"`
	AdvertiserName     string  `json:"advertiser_name"`
	ProjectId          int64   `json:"project_id,omitempty"`
	ProjectName        string  `json:"project_name,omitempty"`
	PromotionId        int64   `json:"promotion_id,omitempty"`
	PromotionName      string  `json:"promotion_name,omitempty"`
	MaterialId         int64   `json:"material_id,omitempty"`
	MaterialName       string  `json:"material_name,omitempty"`
	ImageMode          string  `json:"image_mode,omitempty"`
	Tdate              string  `json:"tdate"`
	PayAmountRoi       float64 `json:"pay_amount_roi,omitempty"`
	ValidPlay          int64   `json:"valid_play,omitempty"`
	TotalPlay          int64   `json:"total_play,omitempty"`
	Click              int64   `json:"click,omitempty"`
	Show               int64   `json:"show,omitempty"`
	Convert            int64   `json:"convert,omitempty"`
	Cost               float64 `json:"cost,omitempty"`
	ConvertCost        float64 `json:"convert_cost,omitempty"`
	ConversionRate     float64 `json:"conversion_rate,omitempty"`
	DeepConvertCnt     int64   `json:"deep_convert_cnt,omitempty"`
	DeepConvertCost    float64 `json:"deep_convert_cost,omitempty"`
	DeepConvertRate    float64 `json:"deep_convert_rate,omitempty"`
	Cpc                float64 `json:"cpc,omitempty"`
	Ctr                float64 `json:"ctr,omitempty"`
	Cpm                float64 `json:"cpm,omitempty"`
	OrderCount         int     `json:"order_count,omitempty"`
	OrderCost          string  `json:"order_cost,omitempty"`
	InAppOrderGmv      string  `json:"in_app_order_gmv,omitempty"`
	InAppOrderRoi      string  `json:"in_app_order_roi,omitempty"`
	PlayDuration3s     int64   `json:"play_duration_3s,omitempty" gorm:"column:play_duration_3s"`
	PlayDuration3sRate float64 `json:"play_duration_3s_rate,omitempty" gorm:"column:play_duration_3s_rate"`
	VideoId            string  `json:"video_id,omitempty"`
	ImgUrl             string  `json:"img_url,omitempty"`
	Inefficient        int     `json:"inefficient,omitempty"`
	Play25FeedBreak    int64   `json:"play_25_feed_break,omitempty" gorm:"column:play_25_feed_break"`
	Play50FeedBreak    int64   `json:"play_50_feed_break,omitempty" gorm:"column:play_50_feed_break"`
	Play75FeedBreak    int64   `json:"play_75_feed_break,omitempty" gorm:"column:play_75_feed_break"`
	Play99FeedBreak    int64   `json:"play_99_feed_break,omitempty" gorm:"column:play_99_feed_break"`
}

// BeforeCreate GORM 的钩子函数，会在创建记录前被调用
func (r *ReportDayMaterial) BeforeCreate(tx *gorm.DB) (err error) {
	r.CreateTime = time.Now().Format(time.DateTime) // 设置当前时间
	r.UpdateTime = time.Now().Format(time.DateTime) // 设置当前时间
	return nil
}

func (r *ReportDayMaterial) BeforeUpdate(tx *gorm.DB) (err error) {
	r.UpdateTime = time.Now().Format(time.DateTime) // 设置当前时间
	return nil
}
